package com.gree.order.interceptor;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 全局拦截器
 * @since 1.0.0
 */
@Component
public class OrderCommonInterceptor implements HandlerInterceptor {

    @Value("${shop.portal.url}")
    private String shopPortalUrl;

    @Override
    public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
        //获取Application对象中的url地址
        ServletContext context = request.getSession().getServletContext();
        String orderUrl = (String) context.getAttribute("portalUrl");
        if (StringUtils.isEmpty(orderUrl)){
            context.setAttribute("orderUrl",shopPortalUrl);
        }
        return true;
    }}
